/*
 * Project: daycare-ent
 * Package: com.made2ordersoftware.daycare.domain
 * File: EmailEntity
 * Created on: Sep 15, 2013
 */
/**
 * Copyright (c) 2010 Made 2 Order Software, LLC
 *
 * All rights reserved. No part of this software may be reproduced, stored in a retrieval system, or
 * transmitted in any form or by any means, without the prior written permission of Made 2 Order Software.
 *
 * You may not distribute the URL or redistribute the files to third parties. You may transfer the files onto
 * a single storage device so long as you can prove ownership of the software. You may not reverse engineer,
 * decompile, or disassemble the software or media files. You may not modify or translate the software or
 * media, or distribute copies of the software or media without the written consent of Made 2 Order Software,
 * LLC.
 */
package com.made2ordersoftware.daycare.domain;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.made2ordersoftware.daycare.domain.enums.EmailType;
import com.made2ordersoftware.util.StringUtility;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Entity class representing the email of a registered parent of the day care.
 *
 * @author David Canning <dcannin@gmail.com>
 * @version 1.0.0
 */
@Entity
@Table(name = "email")
@XmlRootElement
public class EmailEntity implements Serializable {

    private static final Logger LOG = LoggerFactory.getLogger(EmailEntity.class);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    private Long id;
    @Basic(optional = false)
    @Column(name = "address")
    private String email;
    @Basic(optional = false)
    @Enumerated(EnumType.STRING)
    private EmailType type;
    @JoinColumn(name = "person_id", referencedColumnName = "id", nullable = false, updatable = false)
    @ManyToOne(optional = true, fetch = FetchType.EAGER)
    private ParentEntity parent;

    /**
     * Create an instance of <code>EmailEntity</code>.
     */
    public EmailEntity() {
    }

    /**
     * Create an instance of <code>EmailEntity</code>.
     *
     * @param emailAddress
     * @param type
     */
    public EmailEntity(String emailAddress, EmailType type) {
        this.email = emailAddress;
        this.type = type;
    }

    /**
     *
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets the id
     *
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the email address
     */
    public String getAddress() {
        return email;
    }

    /**
     * Sets the address part of the email.
     *
     * @param emailAddress the email address to set
     */
    public void setAddress(String emailAddress) {
        this.email = emailAddress;
    }

    /**
     * @return the type of email
     */
    public EmailType getType() {
        return type;
    }

    /**
     * Sets the type of email see @link EmailType
     *
     * @param emailType
     */
    public void setType(EmailType emailType) {
        this.type = emailType;
    }

    /**
     *
     * @return the parent
     */
    public ParentEntity getParent() {
        return parent;
    }

    /**
     * Sets the parent
     *
     * @param parent
     */
    public void setParent(ParentEntity parent) {
        this.parent = parent;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 45 * hash + Objects.hashCode(this.id);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof EmailEntity)) {
            return false;
        }
        EmailEntity other = (EmailEntity) object;
        return Objects.equals(this.id, other.getId());
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("\nEmailEntity{ id=").append(
                StringUtility.ifNotNullToString(getId()));
        sb.append("\n\tParent ID=").append(this.parent.getId());
        sb.append("\n\tEmail Address=").append(this.email);
        sb.append("\n\tType=").append(this.type);
        sb.append("}");
        return sb.toString();
    }

}
